<template>
	<view class="container">
		<view class="container__head">
			<view class="container__head-list">
				<view class="container__head-list--left" v-if="goodType">{{goodType == 1 ? '入库摘要：' : '出库摘要：'}}</view>
				<view class="container__head-list--left" v-else>入库摘要：</view>
				<view class="container__head-list--center">
					<view class="" v-if="!isEdit">{{data.title}}</view>
					<input type="text" :maxlength="30" v-model="data.title" v-else/>
				</view>
			</view>
			<view class="container__head-list">
				<view class="container__head-list--left">使用部门：</view>
				<view class="container__head-list--center">
					<view class="">{{data.obsname}}</view>
				</view>
				<view class="container__head-list--right" v-show="isEdit" @click="select({name:data.obsname,id:data.obsid},'obsname')">选择</view>
			</view>
			<view class="container__head-list">
				<view class="container__head-list--left">供货单位：</view>
				<view class="container__head-list--center">
					<view class="">{{data.supplier}}</view>
				</view>
				<view class="container__head-list--right" v-show="isEdit" @click="selctSupplier">选择</view>
			</view>
			<view class="container__head-list">
				<view class="container__head-list--left">使用项目：</view>
				<view class="container__head-list--center">
					<view class="">{{data.wbsname}}</view>
				</view>
				<view class="container__head-list--right" v-show="isEdit" @click="select({name:data.wbsname,id:data.wbsid},'wbsname')">选择</view>
			</view>
			<view class="container__head-list">
				<view class="container__head-list--left" v-if="goodType">{{goodType == 1 ? '入库备注：' : '出库备注：'}}</view>
				<view class="container__head-list--left" v-else>入库备注：</view>
				<view class="container__head-list--center">
					<view class="" v-if="!isEdit">{{data.remarks}}</view>
					<input type="text" :maxlength="30" v-model="data.remarks" v-else/>
				</view>
			</view>
			<view class="container__head-list">
				<view class="container__head-list--left" v-if="goodType">{{goodType == 1 ? '入库日期：' : '出库日期：'}}</view>
				<view class="container__head-list--left" v-else>入库日期：</view>
				<view class="container__head-list--center">
					<view class="">{{data.plandate}}</view>
				</view>
				<view class="container__head-list--right" v-show="isEdit" @click="selectDate">选择</view>
			</view>
		</view>
		<view class="container-detail-card" v-for="item in list" :key="item.id">
			<view class="container-detail-card__name" :style="{'padding-right': type == 'add'? '100rpx' : '20rpx'}">
				<view class="">
					<text style="margin-right: 20rpx;">{{item.pname}}</text>
					<text style="font-size: 25rpx;color: #aaa;">流水号：{{item.id}}</text>
				</view>
				<view class="" style="margin-top: 10rpx;" v-if="isEdit">
					<image src="@/static/theme/default/camera.png" mode="" @click="photo(item)" v-show="isEdit"></image>
				</view>
			</view>
			<view class="container-detail-card__body">
				<view class="container-detail-card__body--item">
					<view class="container-detail-card__body--item-left">
						<view class="">规格</view>
						<view class="">{{item.ptype}}</view>
					</view>
					<view class="container-detail-card__body--item-right">
						<view class="">数量</view>
						<view class="" v-if="!isEdit">{{item.num}}</view>
						<number-box v-model="item.num" v-else></number-box>
					</view>
				</view>
				<view class="container-detail-card__body--item">
					<view class="container-detail-card__body--item-left">
						<view class="">单价</view>
						<view class="" v-if="!isEdit">{{item.pprice}}</view>
						<input type="number" style="color: #000;" v-model="item.pprice"  @blur="e => ppriceInput(e, item)" v-else/>
					</view>
					<view class="container-detail-card__body--item-right">
						<view class="">金额</view>
						<view class="">{{calcPrice(item.pprice,item.num)}}</view>
					</view>
				</view>
				<view class="container-detail-card__body--item" style="border-bottom: 1rpx solid #eee;">
					<view class="container-detail-card__body--item-left">
						<view class="">单位</view>
						<view class="">{{item.punit}}</view>
					</view>
					<view class="container-detail-card__body--item-right">
						<view class="">税率</view>
						<view class="" v-if="!isEdit">{{item.taxrate}}</view>
						<input class="container-detail-card__body--item-right-input" style="color: #000;" type="number" v-model="item.taxrate" @blur="e => taxrateInput(e, item)" v-if="isEdit"/>
						<view class="container-detail-card__body--item-right-text" v-if="isEdit" @click="selectTaxrate(item)">选择</view>
					</view>
				</view>
			</view>
			<view class="container-detail-card__img">
				<view class="container-detail-card__img-list" v-for="(img,i) in item.images" :key="img.id">
					<image class="container-detail-card__img-list-item" :src="img.img" mode="" @click="previewImg(item.images,i)"></image>
					<image class="container-detail-card__img-list-icon" src="@/static/theme/default/home/henggang.png"  v-show="isEdit" @click="delImg(img,i,item.images)"></image>
				</view>
			</view>
			<view class="container-detail-card--del" v-if="type == 'add'"  @click="delCbs(item)">
				<image src="@/static/theme/default/home/henggang.png" mode=""></image>
			</view>
		</view>
		<view class="container-btn" v-if="type == 'add'">
			<u-button type="primary" text="+添加明细" color="green" @click="select('','add')"></u-button>
			<view class="container-btn-tips">*保存后物料种类无法变更，如需变更请删除入库单重新登记</view>
		</view>
		<view class="container-btn" v-if="type == 'edit' && isEdit">
			<u-button type="primary" text="删除" color="#fa3534" @click="delGood"></u-button>
		</view>
		<view class="container-btn" v-if="type == 'edit' && isDel">
			<u-button type="primary" text="删除" color="#fa3534" @click="delInGood"></u-button>
		</view>
		<view class="container-check-box" v-if="type == 'check'">
			<view class="container-check-btn">
				<view class="container-check-btn-out">
					<u-button 
					:customStyle="{'width': '180rpx','height': '80rpx','border': '2rpx solid #ddd','box-sizing': 'border-box'}" 
					type="primary"
					 text="审核出库" 
					 color="#ff9900" 
					 @click="goodsOut"></u-button>
				</view>
				<view class="container-check-btn-reject">
					<u-button 
					:customStyle="{'width': '120rpx','height': '80rpx','color': '#000','border': '2rpx solid #ddd','box-sizing': 'border-box'}" 
					type="primary" 
					text="驳回" 
					color="#fff" 
					@click="checkGoods(-1)"></u-button>
				</view>
				<view class="container-check-btn-agree">
					<u-button 
					:customStyle="{'width': '120rpx','height': '80rpx'}" 
					type="primary" 
					text="审核" 
					color="#2979ff" 
					@click="checkGoods(2)"></u-button>
				</view>
			</view>
		</view>
		
		<!-- 供货单位选择 -->
		<u-popup :show="supplierVisible" mode="center" round="20" @close="supplierVisible = false" @open="supplierVisible = true">
			<view class="taxrate-popup">
				<view class="taxrate-popup__list" hover-class="clickable" v-for="item in supplier" @click="confirmSupplier(item)">
					{{item.name}}
				</view>
			</view>
		</u-popup>
		<!-- 税率选择 -->
		<u-popup :show="taxrateVisible" mode="center" round="20" @close="taxrateVisible = false" @open="taxrateVisible = true">
			<view class="taxrate-popup">
				<view class="taxrate-popup__list" hover-class="clickable" v-for="item in taxrateColumns" @click="confirmTaxrate(item)">
					{{item.nameA}}
				</view>
			</view>
		</u-popup>
		<!-- 日期选择 -->
		<u-datetime-picker
				:show="dateVisble"
				:closeOnClickOverlay="true"
				v-model="date"
				mode="date"
				@confirm="confirmDate"
				@cancel="dateVisble = false" 
				@close="dateVisble = false"
		></u-datetime-picker>
		<!-- 审核出库日期 -->
		<u-datetime-picker
				:show="goodOutVisible"
				:closeOnClickOverlay="true"
				v-model="goodOutDate"
				mode="date"
				@confirm="confirmGoodOutDate"
				@cancel="goodOutVisible = false" 
				@close="goodOutVisible = false"
		></u-datetime-picker>
	</view>
</template>

<script>
	import _custom from '@/common/_custom.js'
	import _data from '@/common/_data.js'
	import moment from 'moment'
	import {uploadImages,formatImg} from '@/common/custom_util.js'
	import NumberBox from '@/components/custom/number-box/number-box.vue'
	
	export default {
		components: {
			NumberBox
		},
		data() {
			return {
				type: 'edit',//该页面类型：edit:编辑、add:新增
				data: {
					obsname: '',
					supplier: '',
					wbsname: '',
					remarks: '',
					plandate: moment().format('YYYY-MM-DD'),
				},
				list: [],
				isEdit: false,//页面是否可编辑
				supplierVisible: false,//供货单位弹窗是否显示
				supplier: [],//供货单位数据
				date: '',//入库日期
				dateVisble: false,//入库日期组件是否显示
				taxrateVisible: false,//税率组件是否显示
				taxrateColumns: [],//税率列表
				taxrate: {},
				obsusername: _data.localData('name'),
				prevPprice: 1,
				isDel: false,//已出库单子是否可删除
				goodOutVisible: false,
				goodOutDate: '',
				goodType: '',
			}
		},
		onLoad(option) {
			if(option.data) {
				this.data = JSON.parse(option.data)
			}
			this.goodType = option.goodType;
			if(this.goodType == 1) {//入库单
				this.getGoodsInDetail()
			} else {
				this.getGoodsOutDetail()
			}
			this.date = this.data.plandate;
			this.type = option.type;
			this.goodOutDate = this.data.plandate;
		},
		//由于使用原生导航栏，兼容H5和APP需要分开写
		onReady() {
			// #ifdef APP-PLUS
			let pages = getCurrentPages();
			let page = pages[pages.length - 1];
			let currentWebview = page.$getAppWebview();
			let titleNView = currentWebview.getStyle().titleNView;
			// #endif
			// #ifdef H5
			let text = document.getElementsByClassName('uni-btn-icon')[1]
			// #endif
			switch(this.type) {
				case 'edit'://入库详情
					if(!this.goodType) {
						this.getGoodsInDetail();
					}
					if(this.data.myuser == this.obsusername && this.data.flag == 2) {//已审核可删除
						this.isDel = true;
					}
					// #ifdef H5
					if(this.data.myuser != this.obsusername || !(this.data.flag == -1 || this.data.flag == 1)) {
						text.innerHTML = ''
						this.isEdit = false;
					}
					// #endif
					// #ifdef APP-PLUS
					if(this.data.myuser != this.obsusername || !(this.data.flag == -1 || this.data.flag == 1)) {
						titleNView.buttons[0].text = '';
						this.isEdit = false;
					}
					currentWebview.setStyle({
						titleNView: titleNView
					});
					// #endif
					break;
				case 'add'://新增入库
					this.isEdit = true;
					// #ifdef APP-PLUS
					titleNView.buttons[0].text = '保存';
					currentWebview.setStyle({
						titleNView: titleNView
					});
					// #endif
					// #ifdef H5
					text.innerHTML = '保存'
					// #endif
					break;
				default:
					this.getGoodsInDetail();
					this.isEdit = false;
					// #ifdef APP-PLUS
					titleNView.buttons[0].text = '';
					currentWebview.setStyle({
						titleNView: titleNView
					});
					// #endif
					// #ifdef H5
					text.innerHTML = ''
					// #endif
					break;
			}
		},
		//点击导航栏触发
		onNavigationBarButtonTap(e) {
			if(this.type == 'edit') {
				//判断是否是当前用户
				if(this.data.myuser != this.obsusername) return
				//判断当前入库单状态。2：已出库
				if(!(this.data.flag == -1 || this.data.flag == 1)) return
			}
			let that = this;
			// #ifdef APP-PLUS
			let pages = getCurrentPages();
			let page = pages[pages.length - 1];
			let currentWebview = page.$getAppWebview();
			let titleNView = currentWebview.getStyle().titleNView;
			if(this.type == 'edit') {
				if(!this.isEdit) {
					titleNView.buttons[0].text = '保存';
					this.isEdit = true;
				} else if(this.isEdit && this.checkSubmit()) {
					if(this.data.myuser != this.obsusername) return
					titleNView.buttons[0].text = '编辑';
					this.isEdit = false;
					this.updateGoodsIn()
				}
			} else {
				if(this.checkSubmit()) {
					uni.showModal({
						title: '是否保存入库单信息？',
						success: function (res) {
							if (res.confirm) {
								that.saveGoodsIn()
							}
						}
					});
				}
			}
			currentWebview.setStyle({
				titleNView: titleNView
			});
			// #endif
			// #ifdef H5
			let text = document.getElementsByClassName('uni-btn-icon')[1]
			if(this.type == 'edit') {//入库后编辑
				if(!this.isEdit) {
					text.innerHTML = '保存'
					this.isEdit = true;
				} else if(this.isEdit && this.checkSubmit()) {
					text.innerHTML = '编辑'
					this.isEdit = false;
					this.updateGoodsIn()
				}
			} else {//新增入库
				if(this.checkSubmit()) {
					uni.showModal({
						title: '是否保存入库单信息？',
						success: function (res) {
							if (res.confirm) {
								that.saveGoodsIn()
							}
						}
					});
				}
			}
			// #endif
		},
		methods: {
			/**
			 * 获取入库数据
			 */
			getGoodsInDetail() {
				let that = this;
				_custom.getDataJava({
					apiname: 'getGoodsInDetail',
					apiparam: {
						pid: this.data.id
					},
					success(res) {
						that.list = res;
						if(that.goodType == 1 && res.length) {
							that.data.title = res[0].name;
							that.data.obsname = res[0].aname;
							that.data.supplier = res[0].myplan;
							that.data.wbsname = res[0].bname;
							that.data.remarks = res[0].yuanyin;
							that.data.plandate = res[0].plandate;
						}
						that.list.forEach(item => {
							_custom.getDataJava({
								apiname: 'getGoodsInImages',
								apiparam: {
									goodsinid: item.id
								},
								success(result) {
									result.forEach(item => {
										item.img = formatImg(item.savename)
									})
									that.$set(item,'images',result)
								}
							})
						})
					}
				})
			},
			/**
			 * 获取出库数据
			 */
			getGoodsOutDetail() {
				let that = this;
				_custom.getDataJava({
					apiname: 'getGoodsOutDetail',
					apiparam: {
						pid: this.data.id
					},
					success(res) {
						that.list = res;
						if(that.goodType == 2 && res.length) {
							that.data.title = res[0].name;
							that.data.obsname = res[0].aname;
							that.data.supplier = res[0].myplan;
							that.data.wbsname = res[0].bname;
							that.data.remarks = res[0].yuanyin;
							that.data.plandate = res[0].plandate;
						}
						that.list.forEach(item => {
							_custom.getDataJava({
								apiname: 'getGoodsInImages',
								apiparam: {
									goodsinid: item.id
								},
								success(result) {
									result.forEach(item => {
										item.img = formatImg(item.savename)
									})
									that.$set(item,'images',result)
								}
							})
						})
					}
				})
			},
			/**
			 * 更新入库单
			 */
			updateGoodsIn() {
				let that = this;
				_custom.getDataJava({
					apiname: 'updateGoodsInBasicInfo',
					code:2,
					apiparam: {
						id: that.data.id,
						title: that.data.title,
						obsname: that.data.obsname,
						wbsname: that.data.wbsname,
						supplier: that.data.supplier,
						remarks: that.data.remarks,
						plandate: that.data.plandate,
						obsid: that.data.obsid,
						wbsid: that.data.wbsid,
						supplierid: that.data.supplierid,
					},
					success(res) {
						let p = that.list.map(item => {
							return new Promise((resolve1,reject1) => {
								_custom.getDataJava({
									apiname: 'updateGoodsInCbsList',
									code: 2,
									apiparam: {
										id: item.id,
										pname: item.pname,
										ptype: item.ptype,
										punit: item.punit,
										pprice: item.pprice,
										num: item.num,
										taxrate: item.taxrate,
										cbsid: item.cbsid,
										obsid: that.data.obsid,
										wbsid: that.data.wbsid,
									},
									success() {
										let goodsinid = item.id;
										if(!item.images || !item.images.length) {
											resolve1()
											return
										}
										let p = item.images.map(v => {
											if(v.id) {
												return new Promise(resolve2 => resolve2())
											} else {
												return new Promise((resolve2,reject2) => {
													_custom.getDataJava({
														apiname: 'addGoodsInImages',
														code: 13,
														apiparam: {
															goodsinid: goodsinid,
															cbsname: that.data.title,
															extname: v.extension,
															filepath: v.path,
															obsusername: that.obsusername
														},
														success() {
															resolve2()
														},
														fail() {
															reject2()
														}
													})
												})
											}
										})
										Promise.all(p).then(() => {
											resolve1()
										}).catch(() => {
											reject1()
										})
									},
									fail() {
										reject1()
									}
								})
							})
						})
						Promise.all(p).then(res => {
							uni.showToast({
								title: '修改成功',
								icon: 'none'
							})
							that.getGoodsInDetail();
						}).catch(res => {
							uni.showToast({
								title: '修改失败！',
								icon: 'none'
							})
						})
					}
				})
			},
			/**
			 * 保存入库单
			 */
			saveGoodsIn() {
				let that = this;
				_custom.getDataJava({
					apiname: 'addGoodsInBasicInfo',
					apiparam: {
						title: that.data.title,
						obsname: that.data.obsname,
						wbsname: that.data.wbsname,
						supplier: that.data.supplier,
						remarks: that.data.remarks ? that.data.remarks : '',
						plandate: that.data.plandate,
						obsusername: that.obsusername,
						obsid: that.data.obsid,
						wbsid: that.data.wbsid,
						supplierid: that.data.supplierid,
					},
					success(res) {
						if(res.length) {
							let id = res[0].id;
							let promise = that.list.map(item => {
								return new Promise((resolve1,reject1) =>{
									_custom.getDataJava({
										apiname: 'addGoodsInCbsList',
										code: 1,
										apiparam: {
											pid: id,
											myid: item.myid,
											cbscode: item.cbscode,
											pname: item.pname,
											ptype: item.ptype,
											punit: item.punit,
											pprice: item.pprice,
											num: item.num,
											taxrate: item.taxrate,
											cbsid: item.cbsid,
											obsid: that.data.obsid,
											wbsid: that.data.wbsid,
											obsusername: that.obsusername,
										},
										success(result) {
											if(result.length) {
												let goodsinid = result[0].goodsinid;
												if(!item.images || !item.images.length) {
													resolve1()
													return
												}
												let p = item.images.map(v => {
													return new Promise((resolve2,reject2) => {
														_custom.getDataJava({
															apiname: 'addGoodsInImages',
															code: 13,
															apiparam: {
																goodsinid: goodsinid,
																cbsname: that.data.title,
																extname: v.extension,
																filepath: v.path,
																obsusername: that.obsusername
															},
															success() {
																resolve2()
															},
															fail() {
																reject2()
															}
														})
													})
												})
												Promise.all(p).then(result => {
													resolve1()
												}).catch(() => {
													reject1()
												})
											}
										}
									})
								})
							})
							Promise.all(promise).then(result => {
								uni.showToast({
									title: '保存成功！',
									icon: 'none'
								})
								setTimeout(() => {
									uni.navigateBack({
										delta: 1
									})
								},300)
							}).catch(() => {
								uni.showToast({
									title: '保存失败！',
									icon: 'none'
								})
							})
						}
					}
				})
			},
			//获取供货单位列表
			selctSupplier() {
				let that = this;
				_custom.getDataJava({
					apiname: 'getSupplierList',
					apiparam: {
						pid: this.data.id
					},
					success(res) {
						that.supplier = res;
						that.supplierVisible = true;
					}
				})
			},
			/**
			 * 跳转到选择界面
			 * @param {Object} v
			 * @param {Object} t
			 */
			select(v,t) {
				uni.navigateTo({
					url: './select?data=' + JSON.stringify(v) + '&type=' + t
				})
			},
			//从下个页面选择的部门
			editValue(v){
				if(v){
					console.log(v)
					if(v.type == 'obsname') {
						this.data.obsid = v.data[0].id;
					} else if(v.type == 'wbsname') {
						this.data.wbsid = v.data[0].id;
					}
					this.data[v.type] = v.data[0].name;
					this.setTitle()
				}
			},
			//从下个页面选择的物资
			cbsList(v) {
				let that = this;
				if(v) {
					console.log(v)
					let flag = false;
					this.$set(v.data,'num',1);
					this.$set(v.data,'cbsid',v.data.pid);
					this.list.forEach(item => {
						if(item.id == v.data.id) {
							setTimeout(() => {
								uni.showToast({
									title: '已加入列表',
									icon: 'none'
								})
							},300)
							flag = true;
						}
					})
					if(!flag) {
						that.prevPprice = v.data.pprice*1;
						_custom.getDataJava({
							apiname: 'getGoodsInThinkInfo',
							apiparam: {
								myid: v.data.myid,
								obsusername: that.obsusername
							},
							success(res) {
								if(res.length) {
									if(!that.data.title) {
										that.data.title = res[0].title;
										that.data.obsname = res[0].obsname;
										that.data.wbsname = res[0].wbsname;
										that.data.supplier = res[0].supplier;
										that.data.remarks = res[0].remarks;
										that.data.wbsid = res[0].wbsid;
										that.data.remarks = res[0].yuanyin;
										that.data.supplierid = res[0].supplierid;
										that.data.obsid = res[0].obsid;
									}
									v.data.taxrate = res[0].taxrate;
								} else {
									that.$set(v.data,'taxrate',0);
								}
								that.list.push(v.data)
							}
						})
					}
				}
			},
			/**
			 * 删除物资
			 * @param {Object} v
			 */
			delCbs(v) {
				this.list.forEach((item,index) => {
					if(item.id == v.id) {
						this.list.splice(index,1)
					}
				})
			},
			/**
			 * 确认供货单位
			 * @param {Object} v
			 */
			confirmSupplier(v) {
				this.data.supplier = v.name;
				this.data.supplierid = v.id;
				this.supplierVisible = false;
				this.setTitle();
			},
			/**
			 * 确认税率
			 * @param {Object} v
			 */
			confirmTaxrate(v) {
				this.list.forEach(item => {
					if(item.myid == this.taxrate.myid) {
						item.taxrate = v.nameA;
					}
				})
				this.taxrateVisible = false;
			},
			selectDate() {
				this.date = Number(new Date(this.data.plandate));
				this.dateVisble = true;
			},
			selectTaxrate(v) {
				let that = this;
				_custom.getDataJava({
					apiname: 'getDicBSList',
					apiparam: {
						obscode: 'SYS',
						xmcode: 'RKSL'
					},
					success(res) {
						that.taxrateColumns = res;
						that.taxrate = v
						that.taxrateVisible = true;
					}
				})
			},
			/**
			 * 确认日期
			 * @param {Object} v
			 */
			confirmDate(v) {
				this.data.plandate = moment(v.value).format('YYYY-MM-DD');
				this.dateVisble = false;
			},
			calcPrice(v,n) {
				return ((v*1) * (n*1)).toFixed(2)
			},
			checkSubmit() {
				if(!this.data.title) {
					uni.showToast({
						title: '入库摘要不能为空',
						icon: 'none'
					})
					return false
				}
				if(!this.data.obsname) {
					uni.showToast({
						title: '使用部门不能为空',
						icon: 'none'
					})
					return false
				}
				if(!this.data.supplier) {
					uni.showToast({
						title: '供货单位不能为空',
						icon: 'none'
					})
					return false
				}
				if(!this.data.wbsname) {
					uni.showToast({
						title: '使用项目不能为空',
						icon: 'none'
					})
					return false
				}
				if(!this.list.length) {
					uni.showToast({
						title: '至少选择一个物资',
						icon: 'none'
					})
					return false
				}
				return true
			},
			taxrateInput(e,v) {
				let val = e.detail.value*1;
				let t = val;
				if(val < 0) {
					t = 0
				} else if(val > 1) {
					t = 1
				}
				this.$nextTick(() => {
					v.taxrate = t
				})
				return t
			},
			ppriceInput(e,v) {
				let val = e.detail.value*1;
				let t = val;
				if(val <= 0) {
					t = this.prevPprice
				}
				this.$nextTick(() => {
					v.pprice = t
				})
				return t
			},
			//删除入库单
			delGood() {
				let that = this;
				uni.showModal({
					title: '是否删除该入库单？',
					success: function (res) {
						if (res.confirm) {
							_custom.getDataJava({
								apiname: 'delGoodsIn',
								code: 4,
								apiparam: {
									goodsinid: that.data.id
								},
								success(res) {
									uni.showToast({
										title: '删除成功！',
										icon: 'none'
									})
									setTimeout(() => {
										uni.navigateBack()
									},400)
								}
							})
						}
					}
				})
			},
			//删除已审核的出库单
			delInGood() {
				let that = this;
				_custom.getDataJava({
					apiname: 'getGoodsInOutCount',
					apiparam: {
						goodsinid: that.data.id
					},
					success(res) {
						if(res[0].cnt == '0') {
							uni.showModal({
								title: '提示',
								content: '是否删除该已审核入库单?',
								success: function (res) {
									if (res.confirm) {
										_custom.getDataJava({
											apiname: 'delGoodsIn',
											code: 4,
											apiparam: {
												goodsinid: that.data.id
											},
											success(res) {
												uni.showToast({
													title: '删除成功！',
													icon: 'none'
												})
												setTimeout(() => {
													uni.navigateBack()
												},400)
											}
										})
									}
								}
							});
						} else {
							uni.showToast({
								title: '已有物资出库，无法删除',
								icon: 'none'
							})
						}
					}
				})
			},
			//添加照片
			photo(v) {
				let that = this;
				uploadImages({
					sizeType: ['compressed'],
					extension: ['png'],
					count: 9
				},res => {
					uni.hideLoading();
					if(!v.images || !v.images.length) {
						that.$set(v,'images',res)
					} else {
						v.images.push(res[0])
					}
				})
			},
			//删除物料图片
			delImg(v,i,images) {
				let that = this;
				if(this.type == 'add' || !images[i].id) {
					images.splice(i,1)
				} else {
					_custom.getDataJava({
						apiname: 'flagDelGoodsInImage',
						code: 2,
						apiparam: {
							id: v.id,
							code: 'GoodsIn'
						},
						success(res) {
							images.splice(i,1)
						},
						fail() {
							uni.showToast({
								title: '删除失败',
								icon: 'none'
							})
						}
					})
				}
			},
			//预览图片
			previewImg(v,i) {
				let imgs = v.map(item => {
					return item.img
				})
				uni.previewImage({
					current: i,
					urls: imgs
				});
			},
			//设置入库摘要
			setTitle() {
				let obsname = this.data.obsname;
				let supplier = this.data.supplier;
				let wbsname = this.data.wbsname;
				let array = []
				if(obsname) {
					array.push({
						text: obsname,
						index: 0
					})
				}
				if(supplier) {
					array.push({
						text: supplier,
						index: 1
					})
				}
				if(wbsname) {
					array.push({
						text: wbsname,
						index: 2
					})
				}
				for (let i = 0; i < array.length; i++) {
					for (let j = 0; j < array.length; j++) {
						if(array[i] > array[j]) {
							let temp = array[i]
							array[i] = array[j]
							array[j] = temp
						}
					}
				}
				let t = array.map(item => {
					return item.text
				})
				this.data.title = '（入库单）' + t.join('-')
			},
			/**
			 * 审核入库单
			 */
			checkGoods(v) {
				let that = this;
				uni.showModal({
					title: v == -1 ? '是否驳回入库单?' :'是否审核？',
					content: v == -1 ? '' : '审核后无法删除修改',
					success: function (res) {
						if (res.confirm) {
							_custom.getDataJava({
								apiname: 'updateGoodsInFlag',
								code: 2,
								apiparam: {
									goodsinid: that.data.id,
									flag: v
								},
								success() {
									uni.showToast({
										title: '操作成功',
										icon: 'none'
									})
									setTimeout(() => {
										uni.navigateBack()
									},400)
								}
							})
						}
					}
				});
			},
			goodsOut() {
				let that = this;
				uni.showModal({
					title: '是否审核出库？',
					content: '审核后该入库单所有物资全部出库',
					success: function (res) {
						if (res.confirm) {
							that.goodOutVisible = true;
						}
					}
				});
			},
			confirmGoodOutDate(v) {
				let selectDate = moment(v.value).format('YYYY-MM-DD');
				let startDate = this.data.plandate;
				let endDate = moment().format('YYYY-MM-DD');
				let diff1 = moment(selectDate).diff(startDate,'day');
				let diff2 = moment(endDate).diff(selectDate,'day');
				if(diff1 >= 0 && diff2 >= 0) {
					this.goodOutVisible = false;
					this.procGoodsInCheckToOut(selectDate)
				} else {
					uni.showToast({
						title: '日期需要在入库日期和当前日期之间',
						icon: 'none'
					})
				}
			},
			procGoodsInCheckToOut(v) {
				let that = this;
				_custom.getDataJava({
					apiname: 'procGoodsInCheckToOut',
					apiparam: {
						goodsinid: this.data.id,
						obsusername: this.obsusername,
						plandate: v
					},
					success(res) {
						if(res.length && res[0].code == '0') {
							uni.showToast({
								title: '操作成功',
								icon: 'none'
							})
							setTimeout(() => {
								uni.navigateBack()
							},400)
						}
					}
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.container {
		
		&__head {
			background-color: #fff;
			padding: 20rpx;
			
			&-list {
				height: 100rpx;
				display: flex;
				align-items: center;
				
				&--left {
					width: 150rpx;
				}
				
				&--center {
					color: #aaa;
					width: 500rpx;
					
					input,view {
						font-size: 25rpx;
					}
					
					input {
						border-bottom: 1rpx solid #eee;
						padding: 10rpx;
					}
				}
				
				&--right {
					width: calc(100% - 650rpx);
					color: skyblue;
				}
			}
		}
		
		&-detail-card {
			position: relative;
			margin: 30rpx 20rpx;
			border-radius: 20rpx;
			background-color: #fff;
			box-shadow: 0 0 20rpx 2rpx rgba(13, 63, 62, 0.3);
			
			&__name {
				height: 100rpx;
				font-size: 30rpx;
				font-weight: bold;
				padding: 0 20rpx;
				border-bottom: 1rpx solid #eee;
				display: flex;
				justify-content: space-between;
				align-items: center;
				
				image {
					width: 60rpx;
					height: 60rpx;
				}
			}
			
			&__body {
				&--item {
					display: flex;
					align-items: center;
					height: 120rpx;
					border-bottom: 1rpx solid #eee;
					padding-left: 20rpx;
					
					&:last-child {
						border-bottom: 0 solid #eee;
					}
					
					&-left {
						border-right: 1rpx solid #eee;
					}
					
					&-right {
						padding-left: 20rpx;
						position: relative;
						
						&-input {
							width: calc(100% - 85rpx);
						}
						
						&-text {
							position: absolute;
							right: 0;
							bottom: 10rpx;
							width: 80rpx;
							color: skyblue !important;
							font-size: 28rpx !important;
						}
					}
					
					view {
						flex: 1;
						
						input,view {
							font-size: 25rpx;
						}
						
						input {
							border-bottom: 1rpx solid #eee;
							padding-bottom: 10rpx;
							margin-right: 10rpx;
							color: #aaa;
						}
						view {
							
							&:first-child {
								font-size: 28rpx;
							}
							
							&:last-child {
								color: #aaa;
							}
						}
					}
					
				}
			}
			
			&__img {
				overflow-x: scroll;
				display: flex;
				align-items: center;
				padding: 20rpx;
				box-sizing: border-box;
				
				&-list {
					flex: none;
					width: 150rpx;
					height: 150rpx;
					margin-right: 20rpx;
					position: relative;
					
					&-item {
						width: 100%;
						height: 100%;
						border-radius: 10rpx;
					}
					
					&-icon {
						width: 45rpx;
						height: 45rpx;
						position: absolute;
						top: -10rpx;
						right: -15rpx;
					}
				}
			}
			
			&--del {
				position: absolute;
				top: 30rpx;
				right: 30rpx;
				
				image {
					width: 40rpx;
					height: 40rpx;
				}
			}
		}
		
		.taxrate-popup {
			max-height: 550rpx;
			overflow-y: scroll;
			
			&__list {
				width: 600rpx;
				height: 100rpx;
				line-height: 100rpx;
				text-align: center;
				text-overflow: ellipsis;
				overflow: hidden;
				white-space: nowrap;
			}
		}
		
		&-btn {
			margin: 20rpx;
			margin-top: 40rpx;
			
			&-tips {
				font-size: 25rpx;
				color: #aaa;
				margin-top: 10rpx;
			}
		}
		
		&-check-box {
			height: 140rpx;
			position: relative;
			bottom: 0;
			left: 0;
			width: 100%;
		}
		
		&-check-btn {
			position: fixed;
			bottom: 0;
			left: 0;
			width: 100%;
			height: 140rpx;
			background-color: #eee;
			
			&-out {
				position: absolute;
				left: 20rpx;
				top: 50%;
				transform: translateY(-50%);
			}
			
			&-reject {
				position: absolute;
				right: 180rpx;
				top: 50%;
				transform: translateY(-50%);
				width: 100rpx;
				height: 80rpx;
			}
			
			&-agree {
				position: absolute;
				right: 40rpx;
				top: 50%;
				transform: translateY(-50%);
				width: 100rpx;
				height: 80rpx;
			}
		}
		
	}
</style>
